package cn.edu.hqu.wel.shiyan1.model;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Data
public class Movie {
    private Long id;
    private String title;
    private String director;
    private String description;
    private String posterUrl;
    private List<Comment> comments = new ArrayList<>();

    // 添加构造函数
    public Movie(Long id, String title, String director, String description, String posterUrl) {
        this.id = id;
        this.title = title;
        this.director = director;
        this.description = description;
        this.posterUrl = posterUrl;
    }

    private static List<Movie> movies = new ArrayList<>();

    static {
        Movie inception = new Movie(1L, "Inception", "Christopher Nolan", "A thief who steals corporate secrets through the use of dream-sharing technology.", "poster1.jpg");
        inception.getComments().add(new Comment(1L, inception, "Great movie, mind-blowing plot!", 5, 0));
        inception.getComments().add(new Comment(2L, inception, "Amazing visuals and concept.", 4, 0));
        movies.add(inception);

        Movie matrix = new Movie(2L, "The Matrix", "Lana Wachowski, Lilly Wachowski", "A computer hacker learns from mysterious rebels about the true nature of his reality.", "poster2.jpg");
        matrix.getComments().add(new Comment(3L, matrix, "Classic sci-fi, loved the philosophical depth.", 5, 0));
        movies.add(matrix);
    }

    public static List<Movie> getAllMovies() {
        return movies;
    }

    public static Optional<Movie> getMovieById(Long id) {
        return movies.stream().filter(movie -> movie.getId().equals(id)).findFirst();
    }

    public static void addMovie(Movie movie) {
        movies.add(movie);
    }

    public static void deleteMovie(Long id) {
        movies.removeIf(movie -> movie.getId().equals(id));
    }

    public void addComment(Comment comment) {
        this.comments.add(comment);
    }
}